package Collection.hash.HashMap.HashCode;

import java.util.HashMap;

public class HashCode_DEMO_1 {
    public static void main(String[] args) {
        HashMap<Integer, Person> map = new HashMap<>(2);

        map.put(1, new Person(18, "张三"));
        map.put(1, new Person(18, "张三"));
        System.out.println(map.size());
    }
}

class Person {
    private int id;
    private String name;

    public Person(int id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Person) {
            Person personTemp = (Person) obj;
            return this.id == personTemp.id && this.name.equals(personTemp.name);
        }
        return false;
    }
}